﻿using EzFreamWork;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
namespace AssetPoolLoad
{
    public class test : MonoBehaviour
    {
        public GameObject Cube;
        ObjectPool cube;
        float time;

        float fireRate = 0.1f;
        float nextFire = 0;
        void Start()
        {
            cube = new ObjectPool(Cube, "Cube", 0);
        }

        void Update()
        {
            time = Time.deltaTime;
            if (Input.GetMouseButton(0) && Time.time > nextFire)
            {
                nextFire = Time.time + fireRate;
                GameObject temp = cube.GetObjInPool();
                temp.AddComponent<Rigidbody>().AddForce(Camera.main.transform.forward * 1000);
                StartCoroutine(enumerator(temp));
            }
            if (Input.GetMouseButtonDown(1))
            {
                cube.DestoryAllGameObject();
            }
        }

        IEnumerator enumerator(GameObject gameObject)
        {
            yield return new WaitForSeconds(2);
            Destroy(gameObject.GetComponent<Rigidbody>());
            cube.DestoryObjInOutPool(gameObject);
        }
    }

}
